<!--
	///////////////////////////////////////////
	开 发 者：sdrzlyl
	开发时间：2021年01月12日
	修改时间：2021年09月29日
	功能介绍：此API为快捷认证API，请在使用前申请并填写AppId！
	///////////////////////////////////////////
-->
<?php 
require_once './config/config.php';
require '../../config/config.php';
?>
<!doctype html>
<html lang="zh">
<head>
<meta charset="UTF-8">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<title>快捷认证</title>
</head>
<body>
<!--请注意，核心代码区域禁止修改！-->
<!--核心代码区域开始-->
<?php 
if (empty($AppId) or empty($AuthAPI) or empty($API)) {
    echo "请配置config/config.php文件！";
} else {
    $Acc=$_GET['Acc'];
	$Token=$_GET['Key'];
	if(!empty($Acc) && !empty($Token)){
		$ch = curl_init();
		$str =$API."?Acc=".$Acc."&Key=".$Token;
		curl_setopt($ch, CURLOPT_URL, $str);
		curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, true );
		$output =curl_exec($ch);
		$output = mb_convert_encoding($output, "GBK", "UTF-8");
		$output=substr($output,1);
		//var_dump( $output );
		if($output=="666666"){
		    if($_SESSION['link']=="yes"){
		        $_SESSION['link']="no";
		        mysqli_query($con,"INSERT INTO `link` (`id`, `user`, `hy`) VALUES (NULL, '".$_SESSION['member']."', '".$Acc."')");
		        echo "<script>alert('绑定成功！');location='../my.php';</script>";
		    }else{
		        $rs=mysqli_fetch_array(mysqli_query($con,"select * from link where hy = '" . $Acc . "'"));
                if(empty($rs['user'])){
                    echo "<script>alert('认证失败！');location='./api.php';</script>";
                }else{
                    $sql = "select * from member where user = '".$rs['user']."'";
                    $result = mysqli_query($con,$sql);
                    $rs=mysqli_fetch_array($result);
                    $num = mysqli_num_rows($result);
                    if($num){
                        if($rs['state']=="-1"){
                            echo "<script>alert('此账号已注销且已被永久停用！');location='../login.php';</script>";
                        }elseif($rs['state']=="0"){
                            echo "<script>alert('此账号已被封禁，当前无法继续使用！');location='../login.php';</script>";
                        }else{
            			    $_SESSION['member']=$rs['user'];
                		    $ip=getip();
                	    	$result=mysqli_query($con,"INSERT INTO `loginlog` (`id`, `user`, `ops`, `ip`, `safe`, `time`) VALUES (NULL, '".$_SESSION['member']."', '登录成功', '".$ip."', '1', '".date("Y/m/d H:i:s")."')");
                	    	if($_SESSION['url']==""){
        		    	        echo "<script>alert('登录成功！');location='../../index.php';</script>";
        		    	    }else{
        		    	        echo "<script>alert('登录成功！');location='".$_SESSION['url']."';</script>";
        		    	    }
                        }
                    }
                    
                }
		    }
            
			
			//这里请编写认证成功后的操作！
		}else{
			echo "<script>alert('认证失败！');location='./api.php';</script>";
			//echo "<script>alert('认证失败！');location='index.php';</script>";
			//这里请编写认证失败的操作！
		}
	}
}
?>
<!--核心代码区域结束-->
</body>
</html>